package com.wxp.mapper;

import java.util.List;

import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.wxp.entity.Role;
import com.wxp.serviceImpl.UserServiceImpl;

@Mapper
public interface RoleMapper {

	 @Results({
         @Result(property = "roleCode", column = "role_code_"),
         @Result(property = "roleName", column = "role_name_"),
         @Result(property = "roleDesc", column = "role_desc_"),
         @Result(property = "checked", column = "checked_")
	 })
	@Select("select a.role_code_,a.role_name_,a.role_desc_,(case when b.role_code_ is null then 'false' else 'true' end) as checked_ from t_role  a left join (select * from t_user_role c where c.user_id_ = #{userId}) b on a.role_code_ = b.role_code_  ")
    public List<Role> findUserRoleAll(@Param("userId") String userId);
	 
	 @InsertProvider(type = UserServiceImpl.class, method = "saveUserRoleProvider")  
	 void insertUserRole(@Param("userId") String userId,@Param("list") List<Role> role);
}
